#ifndef __TCPTALK_H
#define __TCPTALK_H

#include <rclcpp/rclcpp.hpp> 
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <boost/thread.hpp> 
#include "timer_ros.h"


#define MAXSIZE 1024
// #define TARGETIPADDR "10.10.9.71"
// #define PORTNUM 8000
#define TARGETIPADDR "192.168.1.31"
#define PORTNUM 8001

class Tcp_Talk
{
	public:
		static Tcp_Talk* TcpInstance;
		
		static Tcp_Talk* Tcp_Instance()
		{
			if(TcpInstance == NULL)
				TcpInstance = new Tcp_Talk();
			
			return TcpInstance;
		}
		static rclcpp::Node::SharedPtr node;
		static void set_static_node(rclcpp::Node::SharedPtr n)
		{
			node = n;
		}
	
		Tcp_Talk();
		~Tcp_Talk(void);
		void Tcp_Server_Init(void);
		int Tcp_Client_Init(void);
		void Tcp_Client_Close(void);
		void Tcp_Server_Close(void);
		int Tcp_Client_Write(unsigned char* buf,int len);
		int Tcp_Client_Read(uint8_t* buf);
		int Tcp_Server_Write(unsigned char* buf,int len);
		int Tcp_Server_Read(uint8_t* buf);
		void Tcp_Param_Get(void);
	private:
		int CSocketfd;  //client socket fd
		int SSocketfd;  //server socket fd
		int Clientfd; // client accpet fd
		boost::mutex tcp_client_write_mutex;  //tcp客户端写数据互斥锁 
		std::string TargetIpAddr;
		int PortNum;

		
};

#endif


